


<?php
//-
if (isset($_POST['submit_all'])) {
	ignore_user_abort();
	set_time_limit(0);
	
	$timeout = intval($_POST['delay']);

	$repost = $_POST['repost'];
	echo '<pre>';
	foreach ($repost as $id => $on) {
		$array = array('owner_id' => '-' . $config['groupId'], 'from_group' => 1);
		$text = trim($_POST['texta'][$id]);
		$text = ltrim($text, '.');
		$text = trim($text);
		$text = str_replace('<br>', "\n", $text);
		$text = str_replace('<br/>', "\n", $text);
		$text = str_replace('<br />', "\n", $text);
		echo $text;
		echo '<br /><br />';
		
		$array['message'] = $text;
		
		
		$result = $config['client']->api('wall.post', $array);
		var_dump($result);
		sleep($timeout);
	}
	

	die('finished');
}

if (isset($_POST['vk_submit'])) {
	$groupId = $_POST['groupId'];
	$offset = $_POST['offset'];
	$count = $_POST['count'];
	$minLike = $_POST['min_like'];

	$client = $config['client'];
	$result = $client->api('wall.get', array('owner_id' => '-' . $groupId, 'count' => $count, 'offset' => $offset));

	//var_dump($result);
	unset($result[0]);
	$array = array();
	foreach ($result as $post) {
		if ($post['likes']['count'] <= $minLike) {
			continue;
		}
		if (isset($post['text']) & !isset($post['attachment'])) {
			$array[] = array('like' => $post['likes']['count'],
							'text' => $post['text'],
							'hash' => base64_encode($post['text']));
		}		
	}
	
	var_dump('Total count: ' . count($array) . '<br />');
	
	echo "<form method='post'>";
	foreach ($array as $key => $value) {
		echo "Repost? ({$value['like']}) <input type='checkbox' name='repost[$key]'>";
		echo "<div>{$value['text']}</div>";
		echo "<input type='hidden' name='texta[$key]' value=' . " .addslashes($value['text']). "' />";
		
		echo "<br /><br /><br />";
		
		
	}
	
	echo "<input type='submit' name='submit_all' value='Repost all checked with delay'> 
	<input type='text' name='delay' value='5' /> seconds.</form><br /><br /><br /><br />
	<div id='status'></div>
	<br /><br /><br />";
	
	
}
?>
<script type='text/javascript' src='/ctl/static/jquery.js'></script>

<form method='post'>
Group: <select name='groupId'>

<option value='2536248'>http://vk.com/mnogostatus</option>
<option value='34923985'>http://vk.com/amazing_laugh</option>
</select>

Offset: <input type='text' name='offset' value='0' size='4' /><br />
Count (100 max): <input type='text' name='count' value='100' size='3'/><br />
<3 >= <input type='text' name='min_like' value='800' size='2' /><br />
Type: <select name='type' multiple='multiple'>
<option value='text' selected='selected'>only text</text>
<option value='pic'>only with pic</text>
</select><br />

<input type='submit' name='vk_submit' value='Go' />

</form>